GBML manual / Screen

screen_backdrop

Gives the screen’s backdrop (the color behind everything) a different color on every row, for example a sunset sky. look is one of the BACKDROP_ constants, strength (1 to 3) is how rich the colors are, and speed is how fast the sky slowly drifts. BACKDROP_NONE turns it off.

Works differently on Game Boy - The Game Boy has no colors, so the backdrop becomes bands of its 4 shades (at most 8, each at least 18 rows tall) in the shade the picture leaves for the sky (its color number 0); the sky has to be named in the call.

Works differently on Game Boy Color - The Game Boy Color colors the backdrop row by row in the picture's color 0, so the sky shows only where the picture uses it; only one row-by-row color runs at a time (this, a sprite color or an overlay's Sky color), and the sky is named in the call.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

screen_backdrop(look, strength, speed)

Arguments

NameType
lookbackdrop_look
strengthint
speedreal

Returns

Nothing.

Description

Gives the screen's backdrop a different color on every row, so a flat color becomes a sky. The backdrop is the color the console fills the screen with before it draws anything else. It shows wherever no background and no sprite covers it, so a floor, a wall or a picture drawn over it hides it. It is for rooms with open sky.

A real capture - a striped lighthouse standing on dark ground against a sunset sky that is purple at the top and fades through rose to orange toward the horizon, each row of the screen a slightly different colorA real capture - a striped lighthouse standing on dark ground against a sunset sky that is purple at the top and fades through rose to orange toward the horizon, each row of the screen a slightly different color
A real capture - a striped lighthouse standing on dark ground against a sunset sky that is purple at the top and fades through rose to orange toward the horizon, each row of the screen a slightly different color

The page's first example, screen_backdrop(BACKDROP_SUNSET, 2, 0.25);, five seconds after the room started. The lighthouse and the ground are drawn on top, so they hide the sky; the sky shows everywhere nothing else is drawn. A real picture from a Game Boy Advance ROM.

A real capture, five pictures across ten seconds - the sky slowly sliding from night purple at the start, through rose and orange, to a golden glow at the end, with the lighthouse and the ground in front of it never changingA real capture, five pictures across ten seconds - the sky slowly sliding from night purple at the start, through rose and orange, to a golden glow at the end, with the lighthouse and the ground in front of it never changing
A real capture, five pictures across ten seconds - the sky slowly sliding from night purple at the start, through rose and orange, to a golden glow at the end, with the lighthouse and the ground in front of it never changing

The same room five times over ten seconds. Only the sky changes: at a speed of 0.25 it takes about ten seconds to slide from the dark top of the sky to the golden glow at the bottom.

A real capture, 21 frames played in a loop - ten seconds of the sunset squeezed into a couple of seconds: the sky slides from purple to gold while the lighthouse and the ground stand stillA real capture, 21 frames played in a loop - ten seconds of the sunset squeezed into a couple of seconds: the sky slides from purple to gold while the lighthouse and the ground stand still
A real capture, 21 frames played in a loop - ten seconds of the sunset squeezed into a couple of seconds: the sky slides from purple to gold while the lighthouse and the ground stand still

The ten seconds again, as an animated PNG, sped up. A viewer that cannot animate shows only its first frame.

You give it three things:

Which sky

LookWhat it is
BACKDROP_SUNSETnight blue, purple, rose and orange, with a golden glow at the bottom
BACKDROP_STORMalmost black, slate and a cold grey-green, with a pale glow at the horizon. Strength 1 is the same sky washed out white, which is how you make lightning
BACKDROP_DEEPdeep water: bright turquoise at the top, ink-dark navy at the bottom. A slow speed is a dive
BACKDROP_EMBERthe inside of a furnace: black, dark red, hot red and orange, with a white-hot glow at the bottom
BACKDROP_DAWNa sunrise: soft lilac-blue, pink and peach, with a warm pale gold at the bottom. Nothing in it is dark
BACKDROP_DAYa clear day: strong blue at the top, paler and paler until it is almost white at the horizon
BACKDROP_NIGHTink-dark blue at the top with a dim violet glow low down. Nothing in it is bright
BACKDROP_OCEANthe sea on a sunny day: blue sky, a bright horizon low on the screen, and turquoise water that gets darker below it
BACKDROP_FORESTshadowy green at the top, rich greens in the middle, and a sunlit yellow-green mist at the bottom
BACKDROP_DESERTa hot day: blue sky bleached pale near the horizon, then sandy orange. No purple anywhere
BACKDROP_NEONblack-violet, electric purple and hot pink, with a glowing cyan edge at the bottom
BACKDROP_AURORAthe northern lights: a dark sky, a vivid green glow, a band of violet and dark again
BACKDROP_RAINBOWa rainbow: red at the top, then yellow, green, cyan and blue, ending in violet at the bottom. A speed makes the colors flow
BACKDROP_ALARMan alarm: a dark red sky with one bright red band across it. A speed sweeps the band up and down the screen

None of these is the sky you want? screen_backdrop_gradient makes one from three colors you choose.

These skies are made for title screens and cutscenes. When the game is not running there is nothing else asking for the console's few row-by-row effects, so one of them can be a whole sky, and the next two can be a 3D title. In the middle of gameplay you can still use one, but remember it is a slot you are not giving to anything else.

Call it once

You do not need to call it every frame. Call it once - when the room starts is a good time - and the look keeps going by itself. Calling it again with the same look and strength only changes the speed, so it will not restart. Calling it with a different look or strength swaps the sky and keeps its place.

A look belongs to the screen, so there is nothing to remember and nothing to lose: the screen has one backdrop, and there is one way to turn it off.

Turning it off

screen_backdrop(BACKDROP_NONE, 0, 0);

This gives its slot back straight away. The last two numbers are ignored, but they have to be there. When a room is loaded - you change room, or restart the one you are in - the look ends by itself, so a new room that wants a sky asks for its own.

Always destroy it, do not hide it. There is no way to hide a look, on purpose: something hidden would look gone but would still be using up one of the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why. Off always means the slot is free.

What it costs

A look uses one of the 8 row-by-row effects the console has, and no matrix and no sprite. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row - draw_sprite_ripple and draw_text_3d use them too. You can see how many are in use on the debug screen: the line called H-BLANK shows how many are in use now, the most there have been, and the limit.

The sky itself costs a little memory and a little time, once. The cartridge holds only each sky's few colors; when you ask for one, the console works out all 320 rows of it - about a sixth of a frame, which you will not notice in a room that is just starting - and keeps them in 640 bytes of memory. Every sky, and every screen_backdrop_gradient, shares those same 640 bytes, so the tenth sky you use costs the memory of the first. Asking again for the same look and strength costs almost nothing, which is why it is safe to call from a Step event, though calling it once is tidier.

Picking the sky with a variable (screen_backdrop(my_sky, 2, 0)) is fine too: it only keeps the colors of all the skies, a few dozen bytes each.

When there is no room

Ask for more than there is and the game does not skip it. A development build stops with a message that says how many slots there are and names every look that is holding one, so you know which one to turn off. A release build, which has no way to stop and show a message, shows no sky. It never half-works.

Example

screen_backdrop(BACKDROP_SUNSET, 2, 0.25);

A sunset sky that slowly sets, drawn from the moment the room starts.

if (btn_pressed(BTN_A)) {
    screen_backdrop(BACKDROP_SUNSET, 3, 0);
}

A full-colour sunset that stands still, started when A is pressed. Pressing A again changes nothing, because it is the same look.

To go back to the plain screen, use screen_backdrop(BACKDROP_NONE, 0, 0) as shown above.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the look is on, and no matrix and no sprite. The sky is worked out when you ask for it, from a few colors kept in the cartridge, into 640 bytes of memory that every sky and every screen_backdrop_gradient shares; that takes about a sixth of a frame the first time and almost nothing when you ask again for the same look and strength. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. Call it once, not every frame: calling it again with the same look only changes its speed. A look stays until you turn it off or a room is loaded (a restart counts). Turning it off with BACKDROP_NONE hands the slot back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one, a development build stops with a message that names every look holding a slot; a release build draws nothing. The in-game debug overlay shows the count as H-BLANK.

See also: BACKDROP_SUNSETBACKDROP_NONEscreen_backdrop_gradientdraw_sprite_rippledraw_text_3d